package com.tgy.leetcode;

import java.util.HashMap;

/**
 * @Author: tgy
 * @Date: 12/27/20 4:16 PM
 *
 * https://leetcode-cn.com/problems/isomorphic-strings/
 */
public class _205_同构字符串 {

    public boolean isIsomorphic(String s, String t) {

        char[] sChars = (s).toCharArray();
        char[] tChars = (t).toCharArray();

        HashMap<Character, Character> sMap = new HashMap<>(sChars.length);
        HashMap<Character, Character> tMap = new HashMap<>(tChars.length);

        for (int i = 0; i < sChars.length; i++) {

            Character tVal = sMap.get(sChars[i]);
            if (tVal != null && (tVal != tChars[i])) {

                return false;
            }

            Character sVal = tMap.get(tChars[i]);

            if (sVal != null && (sVal != sChars[i])) {

                return false;
            }

            sMap.put(sChars[i],tChars[i]);
            tMap.put(tChars[i],sChars[i]);
        }

        return true;
    }

}
